﻿using Microsoft.VisualStudio.Shell;
using System;
using System.Runtime.InteropServices;
using System.Threading;
using Task = System.Threading.Tasks.Task;

namespace JoinBoxAlignPlug
{
    [PackageRegistration(UseManagedResourcesOnly = true, AllowsBackgroundLoading = true)]
    [Guid(JoinBoxAlignPlugPackage.PackageGuidString)]
    [ProvideMenuResource("Menus.ctmenu", 1)]
    public sealed class JoinBoxAlignPlugPackage : AsyncPackage
    {
        public const string PackageGuidString = "2c7877f3-2912-4021-9fab-1fd6aed6f38a";

        //public static DTE2 vsDTE2 { get; set; }

        protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress<ServiceProgressData> progress)
        {
            // 当异步初始化时，当前线程可能是的背景线程。切换到UI线程后需要UI线程的任何初始化。
            await this.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);

            // 在加载这里完成获取dTE再传给其他对象.
            // 初始化获取DTE对象,是用AsyncPackage拿的.异步
            //vsDTE2 = await GetServiceAsync(typeof(DTE)) as DTE2;

            //所有的命令在这里注册
            await CmdAlign.InitializeAsync(this);
            await CmdDisableSave.InitializeAsync(this);
        }
    }
}
